package com.xunfang.shareaddress;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.xunfang.shareaddress.method.Communicates;

/**
 * 
 * 用户注册界面
 * 
 */
public class RegisteredActivity extends Activity {
	private EditText rusername, rpassword;
	private Button rcannel, rok;

	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.registeruser);

		rusername = (EditText) findViewById(R.id.rusername);
		rpassword = (EditText) findViewById(R.id.rpassword);
		rcannel = (Button) findViewById(R.id.rcannel);
		rok = (Button) findViewById(R.id.rok);
		rcannel.setOnClickListener(new ROnButtonClick());
		rok.setOnClickListener(new ROnButtonClick());

	}

	class ROnButtonClick implements OnClickListener {

		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.rcannel:
				finish();
				break;
			case R.id.rok:
				if (rusername.getText().toString() == null) {
					Toast.makeText(RegisteredActivity.this, "帐号不能为空！", 0)
							.show();
				}
				if (rpassword.getText().toString() == null) {
					Toast.makeText(RegisteredActivity.this, "帐号不能为空！", 0)
							.show();
				}
				if ((rusername.getText().toString() != null)
						&& (rpassword.getText().toString() != null)) {
					boolean flag = false;
					Communicates communicates = new Communicates();
					flag = communicates.Register(
							rusername.getText().toString(), rpassword.getText()
									.toString());
					if (flag) {
						Toast.makeText(RegisteredActivity.this, "注册成功！", 0)
								.show();
						finish();
					} else {
						Toast.makeText(RegisteredActivity.this, "用户已存在！", 0)
								.show();
					}
				}
				break;
			default:
				break;
			}

		}
	}
}
